package mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class Insert {
	static String insertsql =  "insert into employer values(?,?)";
	public static void main(String[] args)
	{
	     try {
	          Class.forName("com.mysql.cj.jdbc.Driver");     //加载MYSQL JDBC驱动程序   
	          //Class.forName("org.gjt.mm.mysql.Driver");
	         System.out.println("Success loading Mysql Driver!");
	        }
	        catch (Exception e) {
	          System.out.print("Error loading Mysql Driver!");
	          e.printStackTrace();
	        }
	     try {
	    	 Connection connect = DriverManager.getConnection(
		              "jdbc:mysql://172.16.63.135/test","root","000000");
	    	 
		       PreparedStatement Statement=connect.prepareStatement(insertsql);
		       
		       Statement.setInt(1,1);
		       Statement.setString(2, "beijing");
		       Statement.executeUpdate();
		       System.out.println("插入成功！");
	     }

	       
	     catch(SQLException e)
		   {
	    	 e.printStackTrace();
	    	 System.out.println("插入失败！");
		   }
	 }

}
